
export const claerMap = (map)=>{
    const layers = map.getLayers().getArray()
    for (let i = layers.length - 1; i >= 0; i--) {
      const layer = layers[i]
      // 检查图层是否是底图图层，如果不是，则销毁它
      if (!isBaseLayer(layer)) {
        let source = layer.getSource()
        if (source) {
          source.clear()
        }
      }
      map.getInteractions().forEach(interaction => {
        if (interaction instanceof ol.interaction.Draw) {
          console.log(interaction)
          map.removeInteraction(interaction); // 移除绘制交互
        }
    })
  }
}
    
    // 来判断一个图层是否是原始底图图层
    function isBaseLayer(layer) {
      if (
        layer.get('name') == 'guanggu' ||
        layer.get('name') == 'ditu1' ||
        layer.get('name') == 'ditu2'
      ) {
        return true
      } else {
        return false
      }
    }

